package com.argticling.service;

import com.argticling.dao.interf.ArticleDAO;
import com.argticling.dao.interf.DublinCoreDAO;
import com.argticling.model.Article;
import com.argticling.model.DublinCore;
import com.argticling.model.User;
import com.argticling.model.chanel.ChannelsManager;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

public class ArticleService {
	@Autowired
    private DublinCoreDAO dublinCoreDao;
	@Autowired
    private ArticleDAO articleDao;
	
	
    public DublinCoreDAO getDublinCoreDao() {
		return dublinCoreDao;
	}

	public void setDublinCoreDao(DublinCoreDAO dublinCoreDao) {
		this.dublinCoreDao = dublinCoreDao;
	}

	private ChannelsManager channelsManager;
    
    public void delete(String articleId){
        articleDao.delete(articleId);
    }

    public void persist(Article article){
        articleDao.persist(article);
    }

    public Article getArticle(String id) {
    	return articleDao.getById(id);
    }

    public List<Article> getArticles(DublinCore dublinCore) {
        return null;//todo completar
    }
    
    public List<Article> getAllArticles(){
    	List<Article> articles;
    	return null;
    }

    public List<Article> getLastArticles(){
    	List<DublinCore> dublinCore = dublinCoreDao.getLastArticles();
    	return articleDao.getLastArticles(dublinCore);
    }
    
    public List<Article> getLastArticles(String section){
    	List<DublinCore> dublinCore = dublinCoreDao.getLastArticles(section);
    	return articleDao.getLastArticles(dublinCore);
    }

    public void publish(Article article){
        article.setPublished(true);
        persist(article);
  //      channelsManager.send(article);
    }
    
	private void sendMailToSubscriptors(User author, Article article,
			List<String> subscriptors) {
		ArgticlingEmailSender emailSender = new ArgticlingEmailSender(author,
				article, subscriptors);
		emailSender.sendMailToSubscriptors();
	}

    public ArticleDAO getArticleDao() {
        return articleDao;
    }

    public void setArticleDao(ArticleDAO articleDao) {
        this.articleDao = articleDao;
    }

    public ChannelsManager getChannelsManager() {
        return channelsManager;
    }

    public void setChannelsManager(ChannelsManager channelsManager) {
        this.channelsManager = channelsManager;
    }
}
